#ifdef WIN32
#include<windows.h>
#endif
#include<GL/glut.h>
#include<GL/gl.h>

int screenWidth = 640;
int screenHeight = 480;


class GLintPoint {

public:
	GLint x,y;
};

void drawDot(GLint x, GLint y)
{
	glBegin(GL_POINTS);
		glVertex2i(x,y);
	glEnd();
}

void myInit()
{
	glClearColor(1.0, 1.0, 1.0, 0);
	glColor3f(0.0f, 0.0f, 0.0f);
	glPointSize(4.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, screenWidth, 0.0, screenHeight);
}

void myDisplay()
{

	//glPolygonMode(GL_FRONT, GL_LINE);
	GLintPoint T[3] = {{100,50}, {100,130}, {150,130}};
	glClear(GL_COLOR_BUFFER_BIT);

	int xCenter = screenWidth/2;
	int yCenter = screenHeight/2;
//	glBegin(GL_POLYGON);
//		glVertex2i(xCenter - 60,yCenter - 60);
//		glVertex2i(xCenter + 60,yCenter - 60);
//		glVertex2i(xCenter + 60,yCenter + 60);
//		glVertex2i(xCenter - 60,yCenter + 60);
//	glEnd();

	glFlush();
}

void myReshape(GLsizei w, GLsizei h)
{
	screenWidth = w;
	screenHeight = h;
	glViewport(0, 0, screenWidth, screenHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0,screenWidth,0.0, screenHeight);
}

void myMouse(int button, int state, int x, int y)
{
	static GLintPoint corner[2];
	static int numCorners = 0;
	if(button == GLUT_LEFT_BUTTON && (state == GLUT_DOWN || state == GLUT_UP))
	{
		corner[numCorners].x = x;
		corner[numCorners].y = screenHeight - y;
		numCorners++;

		if(numCorners == 2)
		{
			glBegin(GL_LINES);
				glVertex2f((GLfloat) corner[0].x, (GLfloat) corner[0].y);
				glVertex2f((GLfloat) corner[1].x, (GLfloat) corner[1].y); //draw the line
			glEnd();

			numCorners = 0;
		}
	}
	else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
		glClear(GL_COLOR_BUFFER_BIT);

	glFlush();

}




int main(int argc, char ** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(screenWidth, screenHeight);
	glutInitWindowPosition(100, 150);
	glutCreateWindow("my first attempt");
	glutDisplayFunc(myDisplay);
	glutReshapeFunc(myReshape);
	glutMouseFunc(myMouse);
	myInit();

	glutMainLoop();
}


